package XynLeen.GraduationProject.Activities;

import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.youth.xframe.widget.XToast;

import org.litepal.crud.DataSupport;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import XynLeen.GraduationProject.Bean.ArrangementBean;
import XynLeen.GraduationProject.Bean.UserBean;
import XynLeen.GraduationProject.R;
import XynLeen.GraduationProject.view.BaseActivity;
import XynLeen.GraduationProject.view.EditLineItem;
import XynLeen.GraduationProject.view.TitleArrowLineItem;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Activity_Personal_Message extends BaseActivity {

    SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    @Bind(R.id.ib_navigation_back)
    ImageButton mIbNavigation_back;
    @Bind(R.id.ib_navigation_add)
    ImageButton mIbNavigation_add;
    @Bind(R.id.tv_navigation_label)
    TextView mTvNavigation;
    @Bind(R.id.groom)
    EditLineItem mGroom;
    @Bind(R.id.bride)
    EditLineItem mBride;
    @Bind(R.id.budget)
    EditLineItem mBudget;
    @Bind(R.id.time)
    TitleArrowLineItem mTime;
    @Bind(R.id.add)
    Button mAdd;

    UserBean mUser;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ButterKnife.bind(this);

        mTvNavigation.setText("婚礼信息");
        mIbNavigation_add.setVisibility(View.INVISIBLE);

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_personal_message;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void initView() {

    }

    @OnClick(R.id.time)
    public void time(View view) {
        // 隐藏软键盘
        ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        //时间选择器
        TimePickerView pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                mTime.setDetail((formatter1.format(date) + ""));
            }
        }).setType(new boolean[]{true, true, true, true, true, false})// 默认全部显示
                .build();
        pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
        pvTime.show();
    }

    @OnClick(R.id.ib_navigation_back)
    public void back(View v){
        switch (v.getId()){
            case R.id.ib_navigation_back:
                finish();
                break;
        }
    }

    @OnClick(R.id.add)
    public void add() {

        if (TextUtils.isEmpty(mGroom.getContent())) {
            XToast.error("新郎姓名不能为空");
            return;
        }
        if (TextUtils.isEmpty(mBride.getContent())) {
            XToast.error("新娘姓名不能为空");
            return;
        }
        if (TextUtils.isEmpty(mBudget.getContent())) {
            XToast.error("预算不能为空");
            return;
        }
        if (TextUtils.isEmpty(mTime.getTextViewVal())) {
            XToast.error("时间不能为空");
            return;
        }

        UserBean bean = new UserBean();
        bean.setGroom(mGroom.getContent());
        bean.setBride(mBride.getContent());
        bean.setBudget(Integer.valueOf(mBudget.getContent()));
        bean.setDate(mTime.getTextViewVal());
        bean.update(1);

//        ContentValues bean=new ContentValues();
//        bean.put("groom",mGroom.getContent());
//        bean.put("bride",mBride.getContent());
//        bean.put("budget",mBudget.getContent());
//        bean.put("date",mTime.getTextViewVal());
//        DataSupport.update(UserBean.class,bean,1);

        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
}
